<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>登录</title>
    <link rel="stylesheet" href="css/style.css">
    <script src="js/jquery.min.js"></script>
    <script src="js/gVerify.js"></script>
    <script src="js/jquery.form.js"></script>
    <script src="js/requestUrl.js"></script>
</head>

<body style="padding-bottom: 0 !important;">
    <div class="login">
        <div class="login_box">
            <div class="logo">
                <img src="img/u257.png" alt="">
            </div>
            <div class="con">
                <div class="tab">
                    <ul>
                        <li class="active">账号登录</li>
                        <li class="none_ac">短信登录</li>
                    </ul>
                </div>
                <div class="tab_content">
                    <ul>
                        <li class="tabs" style="display: block;">
                            <form action='' method='post' id="form1">
                                <div class="input">
                                    <dl>
                                        <input type="text" class="admin" value="" name="userName" placeholder="请输入手机号码">
                                    </dl>
                                    <dl>
                                        <input type="password" class="password" value="" name="password"
                                            placeholder="请输入登录密码">
                                    </dl>
                                    <button type="submit" class="login_btn">登录</button>
                                    <div class="bottom">
                                        <div class="lf">
                                            <input type="checkbox" id="remember">
                                            <label>记住登录状态</label>
                                        </div>
                                        <div class="ri">
                                            <a href="register.html">注册新用户</a>
                                            <a href="Forget_password.html">忘记密码?</a>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </li>
                        <li class="tabs" style="display: none;">
                            <form action="" method='post' id="form2">
                                <div class="input">
                                    <dl>
                                        <input type="text" class="phone" value="" name="tel" placeholder="请输入手机号码"
                                            maxlength="11">
                                    </dl>
                                    <dl>
                                        <input type="text" class="duanxin" name="smsCode" value=""
                                            placeholder="请输入短信验证码">
                                        <span class="get_code">发送验证码</span>
                                    </dl>
                                    <dl>
                                        <input type="text" id="code_input" class="yzm" value="" placeholder="请输入图形验证码">
                                        <div id="v_container"></div>
                                    </dl>
                                    <button class="login_btn login_btn2">登录</button>
                                    <div class="bottom">
                                        <div class="lf">
                                            <input type="checkbox">
                                            <label>记住登录状态</label>
                                        </div>
                                        <div class="ri">
                                            <a href="register.html">注册新用户</a>
                                            <a href="Forget_password.html">忘记密码?</a>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
    <form id="form" style="display: none" action="http://newtest.sdfa.org.cn" method='post'>
        <input id="userId" name="userId">
        <input id="nickName" name="nickName">
    </form>
    <div id="mask">
        <div class="popup">
            <h1>请选择身份</h1>
            <dl style="border:none;margin-top: 30px;height: 30px;line-height: 30px;">
                <label class="choose" style="margin-right: 10px"><input type="radio" class="group_btn"
                        name="personalOrGroup" value="1">个人</label>
                <label class="choose" style="margin-left: 10px;"><input type="radio" class="group_btn"
                        name="personalOrGroup" value="2">团体</label>
            </dl>
            <dl class="group_choose" style="line-height: 30px;margin-top: 20px;">
                <!--                <label class="choose" style="margin-right: 10px;width: auto"><input type="radio" name="groupType"-->
                <!--                                                                                    value="1">体育运营公司</label>-->
                <label class="choose" style="margin-right: 10px;width: auto"><input type="radio" name="groupType"
                        value="2">俱乐部</label>
                <label class="choose" style="margin-right: 10px;width: auto"><input type="radio" name="groupType"
                        value="3">公司</label>
                <label class="choose" style="margin-right: 10px;width: auto"><input type="radio" name="groupType"
                        value="4">学校</label>
                <label class="choose" style="width: auto"><input type="radio" name="groupType" value="6">各地足协</label>
                <label class="choose" style="width: auto"><input type="radio" name="groupType" value="5">其他</label>
            </dl>
            <ul style="margin-top: 10%;">
                <li>
                    <a href="javascript:" class="define">确定</a>
                </li>
                <li>
                    <a href="javascript:;" class="cancel">取消</a>
                </li>
            </ul>
        </div>
    </div>
    <script src="js/layer/layer.js"></script>
    <script>
        var html = $('html').css("height")
        $('body').css("height", html)
        // 请求地址
        var currentIndex = 0;
        $(document).ready(function () {
            $(".tab ul li").click(function () {
                var index = $(this).index();
                if (currentIndex != index) {
                    currentIndex = index;
                    $(this).removeClass("none_ac").addClass("active");
                    $(this).siblings().removeClass("active").addClass("none_ac");
                    var contents = $(".tab_content").find(".tabs");
                    $(contents[index]).show();
                    $(contents[index]).siblings().hide();
                }
            });
            $("#form1").attr("action", getRequestPrefix() + "/user/doLogin");
            $("#form2").attr("action", getRequestPrefix() + "/user/smsDoLogin");
        });

        /**
         * 获取url请求前缀
         * @return http://127.0.0.1/cheliangzhihui
         */
        function getRequestPrefix() {
            // 获取网络协议
            // 获取主机名+端口号
            return urlPrefix = 'http://newtest.sdfa.org.cn/footballAssociation';
            var domainPort = window.location.host;
            // 获取发布项目的名称
            // 获取路径
            var url = window.location.pathname;
            var webApp = url.split('/')[1];
            // http://127.0.0.1/demo
            var urlPrefix = "http://" + domainPort + "/" + webApp;
            return urlPrefix;
        }

        // 账户密码登录
        $('.login_btn').click(function () {
            var username = $(".admin").val();
            var password = $(".password").val();

            $("#form1").ajaxForm(function (data) {
                if (data.msg == "0") {
                    if (username == '') {
                        layer.alert('请输入手机号码', {
                            title: '提示'
                        })
                        return
                    }
                    if (password == '') {
                        layer.alert('请输入登录密码', {
                            title: '提示'
                        })
                        return
                    }
                    sessionStorage.userId = data.userId
                    $("#userId").val(data.userId);
                    if (data.nickName) {
                        sessionStorage.nickName = data.nickName
                        $("#nickName").val(data.nickName);
                    } else {
                        sessionStorage.nickName = ""
                        $("#nickName").val("");
                    }
                    sessionStorage.tel = data.tel;
                    // if (data.personalOrGroup == "2") {
                    //     window.location.href = "http://newtest.sdfa.org.cn/footballAssociation/footBallAdmin/login.html"
                    // } else {
                    // $("#form").submit();
                    $.ajax({
                        url: getRequestPrefix() + '/user/findUseByUserId',
                        type: 'POST',
                        data: {
                            userId: data.userId
                        },
                        dataType: 'JSON',
                        success: function (data) {
                            if (data.user.personalOrGroup == null || data.user
                                .personalOrGroup == "") {
                                $('#mask').fadeIn();
                                $('#mask .popup').css('height', 'auto')
                            } else {
                                goBack()
                            }
                        },
                        error: function (data) {
                            console.log(data)
                        }
                    })
                    // }
                } else {
                    layer.alert(data.msg, {
                        title: '提示'
                    })
                }
            });
        });
        // 短信登录
        var verifyCode = new GVerify("v_container");
        $('.login_btn2').click(function () {
            var phone = $(".phone").val();
            var duanxin = $(".duanxin").val();
            if (phone == '') {
                layer.alert('请输入手机号码', {
                    title: '提示'
                })
                return false
            }
            if (duanxin == '') {
                layer.alert('请输入短信验证码', {
                    title: '提示'
                })
                return false
            }
            var res = verifyCode.validate(document.getElementById("code_input").value);
            if (res) {
                console.log('验证正确');
            } else {
                layer.alert('验证码错误，请重新输入', {
                    title: '提示'
                })
                return false
            }
            $("#form2").ajaxForm(function (data) {
                console.log(data)
                if (data.msg == "0") {
                    sessionStorage.userId = data.userId
                    $("#userId").val(data.userId);
                    if (data.nickName) {
                        sessionStorage.nickName = data.nickName
                        $("#nickName").val(data.nickName);
                    } else {
                        sessionStorage.nickName = ""
                        $("#nickName").val("");
                    }
                    $("#nickName").val(data.nickName);
                    sessionStorage.tel = data.tel;
                    // if (data.personalOrGroup == "2") {
                    //     window.location.href = "http://newtest.sdfa.org.cn/footballAssociation/footBallAdmin/login.html"
                    // } else {
                    $.ajax({
                        url: getRequestPrefix() + '/user/findUseByUserId',
                        type: 'POST',
                        data: {
                            userId: data.userId
                        },
                        dataType: 'JSON',
                        success: function (data) {
                            if (data.user.personalOrGroup == null || data.user
                                .personalOrGroup == "") {
                                $('#mask .popup').css('height', 'auto')
                                $('#mask .popup').css('height', 'auto')
                            } else {
                                goBack()
                            }
                        },
                        error: function (data) {
                            console.log(data)
                        }
                    })
                    //}
                } else {
                    layer.alert(data.msg, {
                        title: '提示'
                    })
                }
            });
        });

        //点击获取验证码 + 短信倒计时
        function countDown() {
            let text = 60;
            $('.get_code').html(text);
            let timer = setInterval(function () {
                if (text == 1) {
                    clearInterval(timer);
                    flag = true;
                    $('.get_code').html('发送验证码');
                } else {
                    text -= 1;
                    flag = false;
                    $('.get_code').html(text);
                }
            }, 1000)
        }

        var flag = true;
        $('.get_code').click(function () {
            if (!flag) return false;
            var phone = $(".phone").val();
            if ($(".phone").val().length < 11) {
                layer.alert('请输入手机号码', {
                    title: '提示'
                })
                return false;
            }
            myAjax('/user/sendLoginSms', {
                    phone: phone
                },
                function (data) {
                    console.log(data)
                    if (data.msg == "0") {
                        layer.alert('发送成功', {
                            title: '提示'
                        })
                        countDown();
                    }
                },
                function (err) {
                    console.log(err)
                })
            // countDown();

        });
        var single;
        $(".group_btn").click(function () {
            single = $("input[name='personalOrGroup']:checked").val();
            if (single == 1) {
                $('.group_choose').hide()
                $('#mask .popup').css('height', 'auto')
            } else if (single == 2) {
                $('.group_choose').show()
                $('#mask .popup').css('height', '340px')
            }
        })
        $('.cancel').click(function () {
            $('#mask').fadeOut();
        })
        $('.define').click(function () {
            var group_type = $("input[name='groupType']:checked").val();
            var pOrG = $("input[name='personalOrGroup']:checked").val();
            if (pOrG == undefined) {
                layer.msg("请选择个人或团体")
                return false
            }
            if (pOrG == 2 && group_type == undefined) {
                layer.msg("请选择团体种类")
                return false
            }
            myAjax('/user/updatePersonalOrGroup', {
                    userId: sessionStorage.userId,
                    personalOrGroup: pOrG,
                    groupType: group_type
                },
                function (data) {
                    if (data.msg == 0) {
                        layer.alert("保存成功", function () {
                            window.location.href = "http://newtest.sdfa.org.cn"
                        })
                    } else {
                        layer.msg(data.msg)
                    }
                },
                function (err) {
                    console.log(err)
                })
        })

        function goBack() {
            if (sessionStorage.history == "2") {
                sessionStorage.history = "3"
                window.location.href = "http://newtest.sdfa.org.cn"
            } else {
                if ((navigator.userAgent.indexOf('MSIE') >= 0) && (navigator.userAgent.indexOf('Opera') < 0)) { // IE
                    if (history.length > 0) {
                        window.history.go(-1);
                    } else {
                        window.location.href = "http://newtest.sdfa.org.cn"
                    }
                } else { //非IE浏览器
                    if (navigator.userAgent.indexOf('Firefox') >= 0 ||
                        navigator.userAgent.indexOf('Opera') >= 0 ||
                        navigator.userAgent.indexOf('Safari') >= 0 ||
                        navigator.userAgent.indexOf('Chrome') >= 0 ||
                        navigator.userAgent.indexOf('WebKit') >= 0) {

                        if (window.history.length > 1) {
                            window.history.go(-1);
                        } else {
                            window.location.href = "http://newtest.sdfa.org.cn"
                        }
                    } else { //未知的浏览器
                        window.history.go(-1);
                    }
                }
            }

        }
    </script>
</body>

</html>